//
//  SFankuiViewController.m
//  News
//
//  Created by dlios on 15-5-22.
//  Copyright (c) 2015年 PEAK. All rights reserved.
//

#import "SFankuiViewController.h"

@interface SFankuiViewController ()<UITextFieldDelegate, UIAlertViewDelegate>

@property (nonatomic, retain) UIAlertView *al;

@end



@implementation SFankuiViewController

- (void)viewWillAppear:(BOOL)animated
{
    self.tabBarController.tabBar.hidden = YES;
}
- (void)viewWillDisappear:(BOOL)animated
{
    self.tabBarController.tabBar.hidden = NO;
}


- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
  
    
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(20, 64, self.view.frame.size.width - 40, 40)];
    label.text = @"谢谢您反馈的意见";
    [label setTextAlignment:NSTextAlignmentCenter];
    [self.view addSubview:label];
    UITextField *textField = [[[UITextField alloc] initWithFrame:CGRectMake(20, 120, self.view.frame.size.width - 40, 120)] autorelease];
    textField.tag = 1000;
    textField.placeholder = @"请提出您要反馈的意见";
    textField.delegate = self;
    textField.textAlignment = NSTextAlignmentLeft;
    
    //外观设置
    //输入框 borderStyle
    [textField setBorderStyle:UITextBorderStyleRoundedRect];
    //清除按钮样式 clearButtonMode
    [textField setClearButtonMode:UITextFieldViewModeAlways];
    [self.view addSubview:textField];
    
    
    UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
    button.frame = CGRectMake(textField.frame.size.width / 2,textField.frame.origin.y + 140, 50, 50);
    [button setTitle:@"提交" forState:UIControlStateNormal];
    [button.layer setBorderWidth:1];
    [button.layer setCornerRadius:25];
    [button addTarget:self action:@selector(fachu) forControlEvents:UIControlEventTouchUpInside];
    button.backgroundColor = [UIColor redColor];
    [button setTintColor:[UIColor whiteColor]];
    [self.view addSubview:button];
    
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"iconfont-fanhui"] style: UIBarButtonItemStylePlain target:self action:@selector(fanhui)];

    
    
}
- (void)fanhui
{
    [self.navigationController popViewControllerAnimated:YES];
}

- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
    //将要点击return按钮时触发该方法
    //让当前textField 失去第一响应者
    [textField resignFirstResponder];
    return YES;
}


- (void)fachu
{
    UITextField *text = (UITextField *)[self.view viewWithTag:1000];
    
   // NSString *str = text.text;
//    NSLog(@"%@", str);
//    
  if (text.text.length != 0) {
//    NSDictionary *dic = [[NSDictionary alloc]initWithObjects:[NSArray arrayWithObject:str] forKeys:[NSArray arrayWithObject:@"content"]];
      self.al = [[UIAlertView alloc] initWithTitle:@"提示" message:@"谢谢您的意见" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
      [_al show];
      [self.view addSubview:_al];
      
   }else{
        UIAlertView *al = [[UIAlertView alloc] initWithTitle:@"提示" message:@"您还没有提出意见" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
        [al show];
        [self.view addSubview:al];
        
    }
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if (buttonIndex == 0) {
        
        UITextField *text = (UITextField *)[self.view viewWithTag:1000];
        [text setText:@""];//重新置为初始的0
       
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
